﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.IO;
namespace DAL
{
    /// <summary>
    ///  巨潮数据库数据访问
    /// </summary>
    public class JCDal
    {
        public List<JCStock> GetStocks()
        {
            string sql = "select OB_SECCODE_0007,OB_SECNAME_0007,F001V_0007 from tb_public_0007 where F003V_0007='A股'";
            DataTable tb = DAL.SqlHelper.ExecuteGetTable(DBManager.Cpdb, System.Data.CommandType.Text, sql, null);
            List<JCStock> lst = new List<JCStock>();
            foreach (DataRow row in tb.Rows)
            {
                JCStock c = new JCStock();
                c._C = DAL.Tools.GetString(row["OB_SECCODE_0007"]);
                c._S = DAL.Tools.GetString(row["F001V_0007"]).ToUpper();
                c._N = DAL.Tools.GetString(row["OB_SECNAME_0007"]);
                c._T = "A股";
                lst.Add(c);
            }
            MainQuoteDBModel.MainQuoteDBEntities mDal = new MainQuoteDBModel.MainQuoteDBEntities();
            var bkLst= mDal.TB_BK.Where(x => x.BK_CODE.StartsWith("002"));
            //得到拼音列表
            Dictionary<string ,string> dicPinYin=new Dictionary<string,string>();
            string [] arrPinYin=File.ReadAllLines(System.Web.HttpContext.Current.Server.MapPath("~/NewCatch/PinYin.txt"));
            foreach(var c in arrPinYin)
            {
                string [] temp=c.Split(' ');
                dicPinYin.Add(temp[0],temp[1]);
            }
            foreach (var c in bkLst)
            {
                JCStock t = new JCStock();
                t._C = c.BK_CODE;
                t._N = c.BK_NAME;
                if (dicPinYin.ContainsKey(c.BK_NAME))
                {
                    t._S = dicPinYin[c.BK_NAME];
                    t._T = "行业板块";
                    lst.Add(t);
                }
            }
            lst.Add(new JCStock(){ _C="000002", _N="A股指数", _S="AGZS", _T="指数"});
            lst.Add(new JCStock(){ _C="000001", _N="上证指数", _S="SZZS", _T="指数"});
            lst.Add(new JCStock(){ _C="399001", _N="深证成指", _S="SZCZ", _T="指数"});
            lst.Add(new JCStock(){ _C="000300", _N="沪深300", _S="HS300", _T="指数"});
            lst.Add(new JCStock(){ _C="399005", _N="中小板指数", _S="ZXBZS", _T="指数"});
            lst.Add(new JCStock(){ _C="399006", _N="创业板指数", _S="CYBZS", _T="指数"});
            lst.Add(new JCStock(){ _C="001006", _N="上证50", _S="SZ50", _T="指数"});
            lst.Add(new JCStock(){ _C="000903", _N="中证100", _S="SZ100", _T="指数"});
            lst.Add(new JCStock(){ _C="000010", _N="上证180", _S="SZ180", _T="指数"});
            lst.Add(new JCStock(){ _C="001027", _N="深证100", _S="SZ100", _T="指数"});
            return lst;
        }
    }
}